﻿package game.account.shop {
	import game.objects.GameObject;
	import game.ui.Button;
	import flash.text.TextField;
	import game.objects.DonatObject;
	import game.lang.Lang;
	import fl.lang.Locale;
	import game.ui.Money;
	import flash.events.MouseEvent;
	
	public class ShopDonatItem extends GameObject {
		
		private function get buyBtn():Button	{ return this.getChildByName('btnBuy') as Button; }
		private function get tfCost():TextField	{ return this.getChildByName('costText') as TextField; }
		private function get tfPlus():TextField	{ return this.getChildByName('plusText') as TextField; }
		
		private var money:Money;
		private var data:DonatObject;
		
		public function ShopDonatItem ( data:DonatObject ):void {
			this.data = data;
			
			money = new Money ( Money.DONAT, data.gold, Money.RIGHT );
			money.x = 20;
			money.y = 42;
			addChild ( money );
			
			if (data.plus>0)
				tfPlus.text = "+"+String(data.plus);
			
			lang.set(tfCost, "IDS_DONAT_COST", {cost: data.cost});
			
			buyBtn.addEventListener ( MouseEvent.CLICK, buyHandler );
		}
		
		private function buyHandler(event:MouseEvent):void {
			this.dispatchEvent ( new ShopDonatEvent ( ShopDonatEvent.BUY, data ) );
		}
	}
}